<?php

namespace EasyTiktok\OpenPlatform;

use EasyTiktok\Kernel\ServiceContainer;
use EasyTiktok\Kernel\Traits\ResponseCastable;
use EasyTiktok\OpenPlatform\Auth\AccessToken;

/**
 * Class Application.
 * @property AccessToken $access_token
 *
 * @author zhaoxiang <zhaoxiang051405@gmail.com>
 */
class Application extends ServiceContainer {

    use ResponseCastable;

    protected array $providers = [
        Base\ServiceProvider::class,
        Auth\ServiceProvider::class
    ];

    /**
     * 开发平台获取预授权的URL
     * @param string $callbackUrl
     * @return string
     * @author zhaoxiang <zhaoxiang051405@gmail.com>
     */
    public function getPreAuthorizationUrl(string $callbackUrl): string {
        $queries = [
            'scope'         => '',
            'state'         => '',
            'client_key'    => $this['config']['client_key'],
            'redirect_uri'  => $callbackUrl,
            'response_type' => 'code'
        ];

        return $this['config']['base_url'] . 'platform/oauth/connect?' . http_build_query($queries);
    }

    /**
     * Handle dynamic calls.
     *
     * @param string $method
     * @param array $args
     *
     * @return mixed
     */
    public function __call(string $method, array $args) {
        return $this->base->$method(...$args);
    }
}
